﻿@model SYJ.Model.Entities.Notice
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <title></title>
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.11.3.min.js"></script>
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Scripts/Common.js"></script>
    <link href="~/Content/kindeditor/themes/default/default.css" rel="stylesheet" />
    <link href="~/Content/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
    <script src="~/Content/kindeditor/kindeditor-all-min.js"></script>
    <script src="~/Content/kindeditor/lang/zh-CN.js"></script>
    <script src="~/Content/kindeditor/plugins/code/prettify.js"></script>
</head>
<body class="layui-container" >
    <div class="layui-row">
        <form class="layui-form" name="form1" action="" method="post">
            <input type="hidden" id="id" name="id" value="@Model.id" />
            <div class="layui-form-item">
                <label class="layui-form-label">选择类型</label>
                <div class="layui-input-block">
                    <select name="type" id="type" lay-verify="required">
                        @{ foreach (SYJ.Model.Entities.NoticeType t in (List<SYJ.Model.Entities.NoticeType>)ViewBag.NoticeTypeList)
                         {
                            <option value='@t.id'> @t.title </option>
                         }}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" value="@Model.title" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">账号状态</label>
                <div class="layui-input-block">
                    <select name="status" id="status">
                        <option value="1">停用</option>
                        <option value="0">正常</option>

                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">


                @Html.TextAreaFor(model => model.explain, new { id = "explain", style = "width:720px;height:400px" })


            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="form1" type="button">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[id="explain"]', {//textarea
                allowFileManager: true,                  //是否允许文件上传
                allowUpload: true,
                fileManagerJson: '/KindEditor/ProcessRequest', //浏览文件方法
                uploadJson: '/KindEditor/UploadImage',          //上传文件方法
                //好像没有啥作用 提交并不会进入此方法
                //afterCreate: function () {
                //    debugger;
                //    var self = this;
                //    K.ctrl(document, 13, function () {
                //        self.sync();
                //        K('form[name=form1]')[0].submit();
                //    });
                //    K.ctrl(self.edit.doc, 13, function () {
                //        self.sync();
                //        K('form[name=form1]')[0].submit();
                //    });
                //}
            });
            prettyPrint();
        });
    </script>

         <script>

             layui.use(['form', 'jquery', 'layedit'], function () {
                 var form = layui.form;
                 var $ = layui.jquery;
                 var layedit = layui.layedit;
                 var status = '@Model.status';
                 if (status == null || status == "") {
                     status = 0;
                 }
                 debugger;
                 $("#status").val(status);
                 if ('@Model.id' != "0") {
                     $("#type").val(@Model.type);
                 }
               
                 
                 form.render('select'); //刷新select选择框渲染
                 //layedit.build('explain'); //建立编辑器

                 //监听提交
                 form.on('submit(form1)', function (data) {
                     debugger;
                     data.field.explain = editor.html();
                     $.ajax({
                         type: "POST",
                         url: '/admin/NoticeMgr/AddOrUp',
                         data: data.field,
                         dataType: "json",
                         //traditional: true, //传数组进后台需要设置该属性
                         success: function (data) {
                             if (data) {
                                 layer.msg("操作成功,2秒后自动关闭", function () {
                                     parent.layui.table.reload('tid');
                                     //当你在iframe页面关闭自身时
                                     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                     parent.layer.close(index); //再执行关闭
                                 });
                             }
                             else {
                                 layer.msg("操作失败");
                             }
                         }
                     });
                     return false;
                 });

             });
    </script>
</body>



</html>